//
//  ViewController.m
//  SY_NavMenu
//
//  Created by 孙悦 on 14-2-11.
//  Copyright (c) 2014年 孙悦. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    self.title = @"首页";
    self.view.backgroundColor = [UIColor grayColor];
    
    _mmMainFX = self.view.bounds.origin.x;
    _mmMainFY = 20 + 44;
//    _mmMainFY = [[UIBaseClass shareInstance] getViewFramOY];
    _clearFlag = YES;
    
//    [self initNavBtn];
    [self initView];
    
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initNavBtn
{

    
    navRightButton= [UIButton buttonWithType:UIButtonTypeCustom];
    [navRightButton setFrame:CGRectMake(281, 7, 30, 30)];
    [navRightButton setBackgroundImage:[UIImage imageNamed:@"c_nav-60-60"] forState:UIControlStateNormal];
    [navRightButton addTarget:self action:@selector(rightNavBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.navigationController.navigationBar addSubview:navRightButton];
    
    //    UIBarButtonItem* rightBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView:navRightButton];
    //    [self.navigationItem setRightBarButtonItem:rightBarButtonItem];
}
-(void)rightNavBtn
{
    if (_clearFlag)
    {
        _clearImg.hidden = NO;
        
        CGAffineTransform navRound =CGAffineTransformMakeRotation(M_PI/-3);//先顺时钟旋转90
        navRound =CGAffineTransformTranslate(navRound,0,0);
        
        [UIView animateWithDuration:0.35f
                              delay:0
                            options:(UIViewAnimationOptionAllowUserInteraction|
                                     UIViewAnimationOptionBeginFromCurrentState)
                         animations:^(void) {
                             
                             _todayButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,0*-10,80*0);//0*-10,45*0);
                             _NewsButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,1*-10,60*1);
                             _brandsButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,2*-10,60*2);
                             _videoButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,3*-10,60*3);
                             _settingButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,4*-10,60*4);
                             _emptyButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,5*-10,60*5);
                             _backButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,6*-10,60*6);
                             _todayButton.alpha = 1;
                             _NewsButton.alpha = 1;
                             _brandsButton.alpha = 1;
                             _videoButton.alpha = 1;
                             _settingButton.alpha = 1;
                             _emptyButton.alpha = 1;
                             _backButton.alpha = 1;
                             
                             [navRightButton setTransform:navRound];
                             
                         }
                         completion:^(BOOL finished) {
                             
                             [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
                                 
                                 _todayButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,0*-10,60.0*0);
                                 _NewsButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,1*-10,60.0*1);
                                 _brandsButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,2*-10,60.0*2);
                                 _videoButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,3*-10,60.0*3);
                                 _settingButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,4*-10,60.0*4);
                                 _emptyButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,5*-10,60.0*5);
                                 _backButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,6*-10,60.0*6);
                                 
                             } completion:NULL];
                         }];
    }
    else
    {
        _clearImg.hidden = YES;
        
        CGAffineTransform navRound =CGAffineTransformMakeRotation(0);//先顺时钟旋转90
        navRound =CGAffineTransformIdentity;
        
        [UIView animateWithDuration:0.35f
                              delay:0
                            options:(UIViewAnimationOptionAllowUserInteraction|
                                     UIViewAnimationOptionBeginFromCurrentState)
                         animations:^(void) {
                             
                             _todayButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,0*-10,45*0);
                             _NewsButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,1*-10,45*0);
                             _brandsButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,2*-10,45*0);
                             _videoButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,3*-10,45*0);
                             _settingButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,4*-10,45*0);
                             _emptyButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,5*-10,45*0);
                             _backButton.transform = CGAffineTransformTranslate(CGAffineTransformIdentity,06*-10,45*0);
                             _todayButton.alpha = 0;
                             _NewsButton.alpha = 0;
                             _brandsButton.alpha = 0;
                             _videoButton.alpha = 0;
                             _settingButton.alpha = 0;
                             _emptyButton.alpha = 0;
                             _backButton.alpha = 0;
                             
                             [navRightButton setTransform:navRound];
                             
                         }
                         completion:^(BOOL finished) {
                             
                             
                         }];
    }
    
    _clearFlag = !_clearFlag;
    
//    NSLog(@"navRightButton = %f,%f",navRightButton.frame.size.width, navRightButton.frame.size.height);
}

-(void)initView
{
    _vFX = _mmMainFX;
    _vFY = _mmMainFY;
    

    _clearImg = [[UIImageView alloc]initWithFrame:CGRectMake(_vFX, _vFY, 320, 460+88-44)];
    _clearImg.backgroundColor = [UIColor colorWithRed:56.0/255 green:92.0/255 blue:99.0/255 alpha:0.9];
    _clearImg.hidden = YES;
    
    _vFX = _mmMainFX;
    _vFY = _mmMainFY;
    _todayButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_todayButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_todayButton setTitle:@"今日封面" forState:UIControlStateNormal];
    
    _NewsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_NewsButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_NewsButton setTitle:@"腕表杂志" forState:UIControlStateNormal];
    
    _brandsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_brandsButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_brandsButton setTitle:@"品牌维基" forState:UIControlStateNormal];
    
    _videoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_videoButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_videoButton setTitle:@"精彩视频" forState:UIControlStateNormal];
    
    _settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_settingButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_settingButton setTitle:@"系统设置" forState:UIControlStateNormal];
    
    _emptyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_emptyButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_emptyButton setTitle:@"关于我们" forState:UIControlStateNormal];
    
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_backButton setFrame:CGRectMake(202, _vFY, 100, 40)];
    [_backButton setTitle:@"返回" forState:UIControlStateNormal];
    
    _todayButton.alpha = 0;
    _NewsButton.alpha = 0;
    _brandsButton.alpha = 0;
    _videoButton.alpha = 0;
    _settingButton.alpha = 0;
    _emptyButton.alpha = 0;
    _backButton.alpha = 0;
    
//    [_todayButton addTarget:self action:@selector(TodayButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    [_NewsButton addTarget:self action:@selector(NewsButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    [_brandsButton addTarget:self action:@selector(brandsBttonAction) forControlEvents:UIControlEventTouchUpInside];
//    [_videoButton addTarget:self action:@selector(videoButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    [_settingButton addTarget:self action:@selector(settingButtonAction) forControlEvents:UIControlEventTouchUpInside];
//    [_emptyButton addTarget:self action:@selector(emptyButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [_backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_clearImg];
    [self.view addSubview:_todayButton];
    [self.view addSubview:_NewsButton];
    [self.view addSubview:_brandsButton];
    [self.view addSubview:_videoButton];
    [self.view addSubview:_settingButton];
    [self.view addSubview:_emptyButton];
    [self.view addSubview:_backButton];
}
//疗程开始 hmStatus=1
//问卷信息 hmStatus=2
//健康评估 hmStatus=4
//健康计划 hmStatus=6
//计划实施 hmStatus=7
//实施总结 hmStatus=9
//全部用户 hmStatus=0

-(void)btnSelect
{
    _clearFlag = NO;
    [self rightNavBtn];
  

}
-(void)back
{
//    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];
    [self rightNavBtn];
}

-(void)viewWillAppear:(BOOL)animated
{
     [self.navigationItem setHidesBackButton:TRUE animated:NO];
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self initNavBtn];
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self rightNavBtn];
    navRightButton.hidden = YES;
    
   
}

@end
